package net.godcode.olivenotes.pages.blog;

import net.godcode.olivenotes.entities.Post;
import net.godcode.olivenotes.entities.PostDAO;

import org.apache.tapestry.ioc.annotations.Inject;
import org.slf4j.Logger;

/**
 * ViewPost
 * 
 * @author Chris Lewis Dec 29, 2007 <chris@thegodcode.net>
 * @version $Id: ViewPost.java 32 2008-01-22 15:14:31Z burningodzilla $
 */
public class ViewPost {
	
	@Inject
	private PostDAO postDao;
	
	@Inject
	private Logger log;
	
	private Post post;
	
	void onActivate(int year, int month, int day, String postName) {
		/*
		 * TODO postName poses a SQL injection threat
		 */
		post = postDao.findByCreatedAndName(year, month, day, postName);
		if(post == null) {
			//TODO no such page!
			throw new RuntimeException("No such post.");
		}
	}
	
	/**
	 * @return the post
	 */
	public Post getPost() {
		return post;
	}
	
}
